package com.dchh.android.suverynew.adapter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.dchh.android.suverynew.R;

import java.util.List;
import java.util.Map;

/**
 * 调查期选择
 *
 * @author zhoudan
 * @date 2015年6月4日
 */
public class CycleListAdapter extends BaseAdapter {

    private Activity activity;
    private List<Map<String, String>> list;

    private String code;

    public CycleListAdapter(Activity activity, List<Map<String, String>> list) {
        this.activity = activity;
        this.list = list;
    }

    public void setCode(String code) {
        this.code = code;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Map<String, String> getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View row = convertView;
        ViewHolder holder;
        if (row == null) {
            holder = new ViewHolder();
            row = LayoutInflater.from(activity).inflate(R.layout.task_cycle_list_item, null);

            holder.id = (TextView) row.findViewById(R.id.cycle_id);
            holder.name = (TextView) row.findViewById(R.id.cycle_name);
            holder.num = (TextView) row.findViewById(R.id.task_num);

            row.setTag(holder);
        } else {
            holder = (ViewHolder) row.getTag();
        }

        Map<String, String> map = getItem(position);
        holder.id.setText(map.get("id"));
        holder.name.setText(map.get("name"));
        return row;
    }

    public final class ViewHolder {
        public TextView id;
        public TextView name;
        public TextView num;
    }
}
